<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>QxOrm: QxOrm - C++ Object Relational Mapping library</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  <td id="projectlogo"><img alt="Logo" src="logo_qxorm.png"/></td>
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">QxOrm
   &#160;<span id="projectnumber">1.4.3</span>
   </div>
   <div id="projectbrief">C++ Object Relational Mapping library</div>
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li class="current"><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li><a href="dirs.html"><span>Directories</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('index.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">QxOrm - C++ Object Relational Mapping library </div>  </div>
</div>
<div class="contents">
<div class="textblock"><p>QxOrm is a C++ library designed to provide Object Relational Mapping (ORM) feature to C++/Qt developers (like Hibernate in Java, or NHibernate in .Net).<br/>
 QxOrm engine is based on a simple and non intrusive mapping function per class to provide :</p>
<ul>
<li><a href="http://www.qxorm.com/qxorm_en/manual.html#manual_30" target="_blank"><b>Persistence</b></a> (based on QtSql Qt module) ;</li>
<li><a href="http://www.qxorm.com/qxorm_en/manual.html#manual_60" target="_blank"><b>Serialization</b></a> (XML and binary, based on Qt and boost serialization engines) ;</li>
<li><a href="http://www.qxorm.com/qxorm_en/manual.html#manual_70" target="_blank"><b>Reflection</b></a> or <a href="http://www.qxorm.com/qxorm_en/manual.html#manual_70" target="_blank"><b>Introspection</b></a> (invoke dynamically class methods and access to properties).</li>
</ul>
<p>QxOrm is developed by Lionel Marty, a software development engineer since 2003.<br/>
 QxOrm library has been accepted into the <a href="http://forum.qt.io/category/24/qt-ambassador-program" target="_blank">Qt Ambassador Program</a>.</p>
<p>For more information about QxOrm library (quick sample, tutorial and forum), please visit : <a href="http://www.qxorm.com/" target="_blank">http://www.qxorm.com/</a>.<br/>
 <a href="http://www.qxorm.com/qxorm_en/manual.html" target="_blank">A manual (user guide) to learn how to work with QxOrm library is available on QxOrm website</a>. <br/>
<br/>
</p>
<h2><a class="anchor" id="quick_sample"></a>
Quick sample using QxOrm library</h2>
<p>1- <em>drug.h</em> file : drug class definition with 3 properties : <em>id</em>, <em>name</em> and <em>description</em> </p>
<div class="fragment"><pre class="fragment"><span class="preprocessor">#ifndef _CLASS_DRUG_H_</span>
<span class="preprocessor"></span><span class="preprocessor">#define _CLASS_DRUG_H_</span>
<span class="preprocessor"></span>
<span class="keyword">class </span>drug
{
<span class="keyword">public</span>:
   <span class="keywordtype">long</span> id;
   QString name;
   QString description;

   drug() : id(0) { ; }
   <span class="keyword">virtual</span> ~drug() { ; }
};

QX_REGISTER_HPP_MY_TEST_EXE(drug, <a class="code" href="classqx_1_1trait_1_1no__base__class__defined.html">qx::trait::no_base_class_defined</a>, 1)

<span class="comment">// This macro is necessary to register &#39;drug&#39; class in QxOrm context</span>
<span class="comment">// param 1 : the current class to register =&gt; &#39;drug&#39;</span>
<span class="comment">// param 2 : the base class, if no base class, use the qx trait =&gt; &#39;qx::trait::no_base_class_defined&#39;</span>
<span class="comment">// param 3 : the class version used by serialization to provide &#39;ascendant compatibility&#39;</span>

<span class="preprocessor">#endif // _CLASS_DRUG_H_</span>
</pre></div><p><br/>
 2- <em>drug.cpp</em> file : setting function implementation - <em>void <a class="el" href="group___qx_register.html#ga0901390a4be805bbd1c555405d13bb5f" title="qx::register_class&lt;T&gt;(T &amp; t) : specialize this template to register a class of type T into QxOrm cont...">qx::register_class()</a></em> </p>
<div class="fragment"><pre class="fragment"><span class="preprocessor">#include &quot;precompiled.h&quot;</span>   <span class="comment">// Precompiled-header with &#39;#include &lt;QxOrm.h&gt;&#39; and &#39;#include &quot;export.h&quot;&#39;</span>
<span class="preprocessor">#include &quot;drug.h&quot;</span>          <span class="comment">// Class definition &#39;drug&#39;</span>
<span class="preprocessor">#include &lt;<a class="code" href="_qx_orm___impl_8h.html" title="QxOrm_Impl.h file should be included in all *.cpp files which depend on QxOrm library if you are usin...">QxOrm_Impl.h</a>&gt;</span>    <span class="comment">// Automatic memory leak detection and boost serialization export macro</span>

QX_REGISTER_CPP_MY_TEST_EXE(drug)   <span class="comment">// This macro is necessary to register &#39;drug&#39; class in QxOrm context</span>

namespace qx {
<span class="keyword">template</span> &lt;&gt; <span class="keywordtype">void</span> <a class="code" href="group___qx_register.html#ga0901390a4be805bbd1c555405d13bb5f" title="qx::register_class&lt;T&gt;(T &amp; t) : specialize this template to register a class of type T into QxOrm cont...">register_class</a>(QxClass&lt;drug&gt; &amp; t)
{
  t.id(&amp; drug::id, <span class="stringliteral">&quot;id&quot;</span>);               <span class="comment">// Register &#39;drug::id&#39; &lt;=&gt; primary key in your database</span>
  t.data(&amp; drug::name, <span class="stringliteral">&quot;name&quot;</span>, 1);      <span class="comment">// Register &#39;drug::name&#39; property with key &#39;name&#39; and version &#39;1&#39;</span>
  t.data(&amp; drug::description, <span class="stringliteral">&quot;desc&quot;</span>);  <span class="comment">// Register &#39;drug::description&#39; property with key &#39;desc&#39;</span>
}}
</pre></div><p><br/>
 3- <em>main.cpp</em> file : basic functionalities of QxOrm library with drug class </p>
<div class="fragment"><pre class="fragment"><span class="preprocessor">#include &quot;precompiled.h&quot;</span>
<span class="preprocessor">#include &quot;drug.h&quot;</span>
<span class="preprocessor">#include &lt;<a class="code" href="_qx_orm___impl_8h.html" title="QxOrm_Impl.h file should be included in all *.cpp files which depend on QxOrm library if you are usin...">QxOrm_Impl.h</a>&gt;</span>

<span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> * argv[])
{
   QApplication app(argc, argv); <span class="comment">// Qt application</span>

   <span class="comment">// Create 3 new drugs</span>
   <span class="comment">// It is possible to use &#39;boost&#39; and &#39;Qt&#39; smart pointer : &#39;boost::shared_ptr&#39;, &#39;QSharedPointer&#39;, etc...</span>
   <span class="keyword">typedef</span> boost::shared_ptr&lt;drug&gt; drug_ptr;
   drug_ptr d1; d1.reset(<span class="keyword">new</span> drug()); d1-&gt;name = <span class="stringliteral">&quot;name1&quot;</span>; d1-&gt;description = <span class="stringliteral">&quot;desc1&quot;</span>;
   drug_ptr d2; d2.reset(<span class="keyword">new</span> drug()); d2-&gt;name = <span class="stringliteral">&quot;name2&quot;</span>; d2-&gt;description = <span class="stringliteral">&quot;desc2&quot;</span>;
   drug_ptr d3; d3.reset(<span class="keyword">new</span> drug()); d3-&gt;name = <span class="stringliteral">&quot;name3&quot;</span>; d3-&gt;description = <span class="stringliteral">&quot;desc3&quot;</span>;

   <span class="comment">// Insert drugs into container</span>
   <span class="comment">// It is possible to use a lot of containers from &#39;std&#39;, &#39;boost&#39;, &#39;Qt&#39; and &#39;qx::QxCollection&lt;Key, Value&gt;&#39;</span>
   <span class="keyword">typedef</span> std::vector&lt;drug_ptr&gt; type_lst_drug;
   type_lst_drug lst_drug;
   lst_drug.push_back(d1);
   lst_drug.push_back(d2);
   lst_drug.push_back(d3);

   <span class="comment">// Init parameters to communicate with a database</span>
   <a class="code" href="classqx_1_1_qx_singleton.html#ac42d9f2442411f1ea7ea0505d224a89c">qx::QxSqlDatabase::getSingleton</a>()-&gt;setDriverName(<span class="stringliteral">&quot;QSQLITE&quot;</span>);
   <a class="code" href="classqx_1_1_qx_singleton.html#ac42d9f2442411f1ea7ea0505d224a89c">qx::QxSqlDatabase::getSingleton</a>()-&gt;setDatabaseName(<span class="stringliteral">&quot;./test_qxorm.db&quot;</span>);
   <a class="code" href="classqx_1_1_qx_singleton.html#ac42d9f2442411f1ea7ea0505d224a89c">qx::QxSqlDatabase::getSingleton</a>()-&gt;setHostName(<span class="stringliteral">&quot;localhost&quot;</span>);
   <a class="code" href="classqx_1_1_qx_singleton.html#ac42d9f2442411f1ea7ea0505d224a89c">qx::QxSqlDatabase::getSingleton</a>()-&gt;setUserName(<span class="stringliteral">&quot;root&quot;</span>);
   <a class="code" href="classqx_1_1_qx_singleton.html#ac42d9f2442411f1ea7ea0505d224a89c">qx::QxSqlDatabase::getSingleton</a>()-&gt;setPassword(<span class="stringliteral">&quot;&quot;</span>);

   <span class="comment">// Create table &#39;drug&#39; into database to store drugs</span>
   QSqlError daoError = qx::dao::create_table&lt;drug&gt;();

   <span class="comment">// Insert drugs from container to database</span>
   <span class="comment">// &#39;id&#39; property of &#39;d1&#39;, &#39;d2&#39; and &#39;d3&#39; are auto-updated</span>
   daoError = <a class="code" href="group___qx_dao.html#gab4400decee849f008633c52a47508995" title="Insert an element or a list of elements into database.">qx::dao::insert</a>(lst_drug);

   <span class="comment">// Modify and update the second drug into database</span>
   d2-&gt;name = <span class="stringliteral">&quot;name2 modified&quot;</span>;
   d2-&gt;description = <span class="stringliteral">&quot;desc2 modified&quot;</span>;
   daoError = <a class="code" href="group___qx_dao.html#ga690042401fc276a1929d311759b69ce2" title="Update an element or a list of elements into database.">qx::dao::update</a>(d2);

   <span class="comment">// Delete the first drug from database</span>
   daoError = <a class="code" href="group___qx_dao.html#ga298e15a5e745ae43d99de9b4279aca3e" title="Delete a line (or list of lines) of a table (database) mapped to a C++ object of type T (registered i...">qx::dao::delete_by_id</a>(d1);

   <span class="comment">// Count drugs into database</span>
   <span class="keywordtype">long</span> lDrugCount = qx::dao::count&lt;drug&gt;();

   <span class="comment">// Fetch drug with id &#39;3&#39; into a new variable</span>
   drug_ptr d_tmp; d_tmp.reset(<span class="keyword">new</span> drug());
   d_tmp-&gt;id = 3;
   daoError = <a class="code" href="group___qx_dao.html#ga2abaf5f2e6de160b099cf2ab74967244" title="Fetch an object t (retrieve all its properties) of type T (registered into QxOrm context) mapped to a...">qx::dao::fetch_by_id</a>(d_tmp);

   <span class="comment">// Export drugs from container to a file under XML format (serialization)</span>
   <a class="code" href="namespaceqx_1_1serialization_1_1qt.html#a23cd5a030d7301735ad5b734813d5159">qx::serialization::xml::to_file</a>(lst_drug, <span class="stringliteral">&quot;./export_drugs.xml&quot;</span>);

   <span class="comment">// Import drugs from XML file into a new container</span>
   type_lst_drug lst_drug_tmp;
   <a class="code" href="namespaceqx_1_1serialization_1_1qt.html#a73923ed86ea7013cbc4fd13f18b3a7ed">qx::serialization::xml::from_file</a>(lst_drug_tmp, <span class="stringliteral">&quot;./export_drugs.xml&quot;</span>);

   <span class="comment">// Clone a drug</span>
   drug_ptr d_clone = <a class="code" href="group___qx_serialize.html#ga80162fe005f1f828a4589defaca4402f" title="qx::clone(const T &amp; obj) : return a boost smart-pointer (qx_shared_ptr&lt;T&gt;) of a new instance of type ...">qx::clone</a>(* d1);

   <span class="comment">// Create a new drug by class name (factory)</span>
   boost::any d_any = <a class="code" href="group___qx_factory.html#ga0bc0922522ca27cff4af086f9b63977d" title="Return a smart-pointer new instance of object (qx_shared_ptr&lt;T&gt;) associated by key sKey using boost::...">qx::create</a>(<span class="stringliteral">&quot;drug&quot;</span>);

   <span class="comment">// Insert drugs container into &#39;qx::cache&#39;</span>
   <a class="code" href="group___qx_cache.html#ga82a848c3fbc52af86aad56812500b0fb" title="Insert object t into the cache with key sKey, associated cost lCost and insertion date-time dt...">qx::cache::set</a>(<span class="stringliteral">&quot;drugs&quot;</span>, lst_drug);

   <span class="comment">// Remove all elements from &#39;qx::cache&#39;</span>
   <a class="code" href="group___qx_cache.html#ga9334ed3464961f8d21fe022ef3a91203" title="Delete all the objects in the cache.">qx::cache::clear</a>();

   <span class="comment">// Create a dummy memory leak</span>
   drug * pDummy = <span class="keyword">new</span> drug();

   <span class="keywordflow">return</span> 0;
}
</pre></div><p><br/>
 4- execute program and trace output debug </p>
<div class="fragment"><pre class="fragment">[QxOrm] <a class="code" href="classqx_1_1_qx_sql_database.html" title="qx::QxSqlDatabase : define all parameters to connect to database and retrieve a valid connection by t...">qx::QxSqlDatabase</a> : <a class="code" href="group___qx_factory.html#ga0bc0922522ca27cff4af086f9b63977d" title="Return a smart-pointer new instance of object (qx_shared_ptr&lt;T&gt;) associated by key sKey using boost::...">create</a> <span class="keyword">new</span> database connection in thread <span class="stringliteral">&#39;3616&#39;</span> with key <span class="stringliteral">&#39;{d315250c-b5c9-46e0-9402-f800368a6673}&#39;</span>
[QxOrm] sql query (78 ms) : CREATE TABLE drug (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name TEXT, desc TEXT)
[QxOrm] sql query (63 ms) : INSERT INTO drug (name, desc) VALUES (:name, :desc)
[QxOrm] sql query (62 ms) : UPDATE drug SET id = :id, name = :name, desc = :desc WHERE id = :id_bis
[QxOrm] sql query (63 ms) : DELETE FROM drug WHERE id = :id
[QxOrm] sql query (0 ms) : SELECT COUNT(*) FROM drug
[QxOrm] sql query (0 ms) : SELECT drug.id AS drug_id_0, drug.name AS drug_name_0, drug.desc AS drug_desc_0 FROM drug WHERE drug_id_0 = :id
[QxOrm] Leaked object at 0xf52ad8 (size 16, src\main.cpp:74)
[QxOrm] **** 1 memory leaks found ****
</pre></div><p><br/>
 5- <em>export_drugs.xml</em> file created by the program </p>
<div class="fragment"><pre class="fragment">&lt;std.vector-boost.shared_ptr-drug-- class_id=<span class="stringliteral">&quot;0&quot;</span> tracking_level=<span class="stringliteral">&quot;0&quot;</span> version=<span class="stringliteral">&quot;0&quot;</span>&gt;
        &lt;<a class="code" href="group___qx_cache.html#gace04518e9bf2dd2fca8449037ceffa19" title="Return the number of objects in the cache.">count</a>&gt;3&lt;/<a class="code" href="group___qx_cache.html#gace04518e9bf2dd2fca8449037ceffa19" title="Return the number of objects in the cache.">count</a>&gt;
        &lt;item_version&gt;1&lt;/item_version&gt;
        &lt;item class_id=<span class="stringliteral">&quot;1&quot;</span> tracking_level=<span class="stringliteral">&quot;0&quot;</span> version=<span class="stringliteral">&quot;1&quot;</span>&gt;
                &lt;px class_id=<span class="stringliteral">&quot;2&quot;</span> tracking_level=<span class="stringliteral">&quot;1&quot;</span> version=<span class="stringliteral">&quot;1&quot;</span> object_id=<span class="stringliteral">&quot;_0&quot;</span>&gt;
                        &lt;<span class="keywordtype">id</span>&gt;1&lt;/<span class="keywordtype">id</span>&gt;
                        &lt;name class_id=<span class="stringliteral">&quot;3&quot;</span> tracking_level=<span class="stringliteral">&quot;0&quot;</span> version=<span class="stringliteral">&quot;0&quot;</span>&gt;name1&lt;/name&gt;
                        &lt;desc&gt;desc1&lt;/desc&gt;
                &lt;/px&gt;
        &lt;/item&gt;
        &lt;item&gt;
                &lt;px class_id_reference=<span class="stringliteral">&quot;2&quot;</span> object_id=<span class="stringliteral">&quot;_1&quot;</span>&gt;
                        &lt;<span class="keywordtype">id</span>&gt;2&lt;/<span class="keywordtype">id</span>&gt;
                        &lt;name&gt;name2 modified&lt;/name&gt;
                        &lt;desc&gt;desc2 modified&lt;/desc&gt;
                &lt;/px&gt;
        &lt;/item&gt;
        &lt;item&gt;
                &lt;px class_id_reference=<span class="stringliteral">&quot;2&quot;</span> object_id=<span class="stringliteral">&quot;_2&quot;</span>&gt;
                        &lt;<span class="keywordtype">id</span>&gt;3&lt;/<span class="keywordtype">id</span>&gt;
                        &lt;name&gt;name3&lt;/name&gt;
                        &lt;desc&gt;desc3&lt;/desc&gt;
                &lt;/px&gt;
        &lt;/item&gt;
&lt;/std.vector-boost.shared_ptr-drug--&gt;
</pre></div> </div></div>
</div>
  <div id="nav-path" class="navpath">
    <ul>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark">&#160;</span>Friends</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(10)"><span class="SelectionMark">&#160;</span>Defines</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>


    <li class="footer">Generated on Sun Dec 11 2016 13:41:03 for QxOrm by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.5.1 </li>
   </ul>
 </div>


</body>
</html>
